/*
 * Filename:    EvaluationOrgController.java
 * Copyright:   2015 中国平安保险（集团）股份有限公司 版权所有
 * Company:     平安科技养老险及健康险系统开发部
 * Create at:   2015-1-29
 */
package com.paic.mhis.hcpms.evaluation.evaluationOrg.evaluationIntegrity.web.controller;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

//import com.paic.mhis.core.auth.biz.service.UserDetails;
//import com.paic.mhis.hcpms.evaluation.common.biz.service.EvaluationJobService;
import com.paic.mhis.hcpms.evaluation.evaluationOrg.evaluationIntegrity.biz.service.EvaluationIntegrityOrgService;
import com.paic.mhis.hcpms.evaluation.evaluationOrg.evaluationIntegrity.constants.EvaluationOrgConstants;
import com.paic.mhis.hcpms.evaluation.evaluationOrg.evaluationIntegrity.web.vo.EvaluationOrgVO;
import com.paic.pafa.appclient.annotation.BizServicesProxy;

@Controller
public class EvaluationIntegrityOrgController {

	@BizServicesProxy
	private EvaluationIntegrityOrgService evaluationIntegrityOrgService;
	//@BizServicesProxy
	//private EvaluationJobService evaluationJobService;

	/**
	 * 定点机构诚信考评列表
	 * 
	 * @param orgVo
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/evaluation/getEvaluationOrgList.do")
	@ResponseBody
	public Map<String, Object> getEvaluationOrgList(@ModelAttribute EvaluationOrgVO vo, HttpServletRequest request) {
		Map<String, Object> map = new HashMap<String, Object>();
		//UserDetails user = (UserDetails) request.getSession().getAttribute("user");
		if (null == vo) {
			vo = new EvaluationOrgVO();
			vo.setLimit(20);
		}
		if (null != vo && vo.getLimit() <= 0) {
			vo.setLimit(20);
		}
		int start = 0, end = 0;
		if (null != vo && vo.getCurrentPage() > 1) {
			start = (vo.getCurrentPage() - 1) * vo.getLimit();
			end = vo.getCurrentPage() * vo.getLimit();
		} else {
			start = 0;
			end = vo.getLimit();
		}
		map.put("start", start);
		map.put("end", end);
		if (vo != null && StringUtils.hasText(vo.getOrgName())) {
			map.put("orgName", vo.getOrgName());
		}
		if (vo != null && StringUtils.hasText(vo.getBedName())) {
			if (vo.getBedName().equals(EvaluationOrgConstants.BEDS)) {
				map.put("bedName", vo.getBedName());
			}
			if (vo.getBedName().equals(EvaluationOrgConstants.NOTBEDS)) {
				map.put("notBeds", vo.getBedName());
			}
		}
		if (vo != null && StringUtils.hasText(vo.getEvaluationYear())) {
			map.put("evaluationYear", vo.getEvaluationYear());
		}
		if (vo != null && StringUtils.hasText(vo.getEvaluationScroe())) {
			map.put("evaluationScroe", vo.getEvaluationScroe());
		}

		if (vo != null && StringUtils.hasText(vo.getProcessStatus())) {
			map.put("status", vo.getProcessStatus());
		}

		map.put("evalautionType", EvaluationOrgConstants.EvaluationType_Org);
		map.put("type", EvaluationOrgConstants.RULE_TYPE01);

		Map<String, Object> result = evaluationIntegrityOrgService.getEvaluationOrgList(map);

		return result;
	}

	/**
	 * 根据年份查询当前需要展示的考评得分名称集合
	 * 
	 * @param orgdto
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/evaluation/getEvaluationName.do")
	@ResponseBody
	public Map<String, Object> getEvaluationName(@ModelAttribute EvaluationOrgVO vo, HttpServletRequest request) {
		List<String> resultList = new ArrayList<String>();
		Map<String, Object> map = new HashMap<String, Object>();
		// String msg = "";
		// if (null == vo) {
		// msg = "参数不能为空";
		// }
		String year = request.getParameter("evaluationYear");
		if ("".equals(year) || year == null) {
			year = new SimpleDateFormat("yyyy").format(new Date());
		} else {
			year = request.getParameter("evaluationYear");
		}
		resultList = evaluationIntegrityOrgService.getEvaluationName(year, EvaluationOrgConstants.RULE_TYPE01);
		map.put("list", resultList);
		return map;
	}
}
